﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DelegateBase
{
    //所谓的委托，通过观察il可知，委托的底层实现就是基于class实现
    //如果是在class外部，独立一个类，如果在class内部，则是类中类

    public class CustomerDelegate
    {
        /// <summary>
        /// 无参数无返回值委托
        /// </summary>
        public delegate void NoReturnNoPara();

        /// <summary>
        /// 有参数无返回值的委托
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        public delegate void NoReturnWithPara(int x, int y);

        /// <summary>
        /// 无参数有返回值的委托
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        public delegate int WithReturnNoPara();

        /// <summary>
        /// 有参数有返回值的委托
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        public delegate int WithReturnWithPara(int x, int y);

        public static Action Action1 { get; set; }

        public static void Show()
        {
            NoReturnNoPara method1 = new(NoReturnNoParaMethod);
            method1.Invoke();

            //实例化一个委托，必须要传入一个和当前委托的参数和返回值完全吻合的方法
            NoReturnWithPara method2 = new(NoReturnWithParaMethod);
            method2.Invoke(1,2);
        }

        public static void NoReturnNoParaMethod()
        {
            Console.WriteLine("This is NoReturnNoParaMethod~~~");
        }

        public static void NoReturnWithParaMethod(int x,int y)
        {
            Console.WriteLine("This is NoReturnWithParaMethod~~~");
        }
    }
}